{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 122
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 5694,
     "status": "ok",
     "timestamp": 1546052213367,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "fEYI9thYKjXi",
    "outputId": "e4b19fc9-9bb2-489c-ba89-94efbe0de645"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pymysql\n",
      "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/ed/39/15045ae46f2a123019aa968dfcba0396c161c20f855f11dea6796bcaae95/PyMySQL-0.9.3-py2.py3-none-any.whl (47kB)\n",
      "\u001b[K    100% |████████████████████████████████| 51kB 2.4MB/s \n",
      "\u001b[?25hInstalling collected packages: pymysql\n",
      "Successfully installed pymysql-0.9.3\n"
     ]
    }
   ],
   "source": [
    "!pip install pymysql"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 153
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 13037,
     "status": "ok",
     "timestamp": 1545736522809,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "W6PXDax4Kq5W",
    "outputId": "a87dbc23-8311-4147-c2d6-84bb2852c0d1"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting git+https://github.com/coreylynch/pyFM\n",
      "  Cloning https://github.com/coreylynch/pyFM to /tmp/pip-req-build-3jy2gc1g\n",
      "Building wheels for collected packages: pyfm\n",
      "  Running setup.py bdist_wheel for pyfm ... \u001b[?25l-\b \b\\\b \b|\b \b/\b \b-\b \b\\\b \bdone\n",
      "\u001b[?25h  Stored in directory: /tmp/pip-ephem-wheel-cache-b2sjt18f/wheels/3b/d9/ef/1b148c527d39344632833679e79b3db1798a40b0f64f917b13\n",
      "Successfully built pyfm\n",
      "Installing collected packages: pyfm\n",
      "Successfully installed pyfm-0.0.0\n"
     ]
    }
   ],
   "source": [
    "!pip install git+https://github.com/coreylynch/pyFM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "Q4EY9z1zKsmv"
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import pymysql\n",
    "import pymysql.cursors\n",
    "from functools import reduce\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import uuid\n",
    "import datetime\n",
    "#from pyfm import pylibfm\n",
    "from sklearn.feature_extraction import DictVectorizer\n",
    "from sklearn.metrics.pairwise import pairwise_distances\n",
    "np.set_printoptions(precision=3)\n",
    "np.set_printoptions(suppress=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "pwH7ys8tbvIj"
   },
   "outputs": [],
   "source": [
    "time_now_str = datetime.datetime.now().strftime(\"%Y-%m-%d-%H-%M-%S\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 740,
     "status": "ok",
     "timestamp": 1546053195451,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "vHZZ3yer84Bp",
    "outputId": "7b49b773-4890-43c5-a888-72700fc50f1b"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2018, 12, 29, 3, 13, 14, 975226)"
      ]
     },
     "execution_count": 16,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.datetime.now()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "ZmYkr3aEKwfs"
   },
   "outputs": [],
   "source": [
    "def get_connection():\n",
    "    return pymysql.connect(host='rm-2zeqqm6994abi7b6dqo.mysql.rds.aliyuncs.com',\n",
    "                               user='noone',\n",
    "                               password='Huawei12#$',\n",
    "                               db='recsys',\n",
    "                               port=3306,\n",
    "                               charset ='utf8',\n",
    "                               use_unicode=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "W2RohtZiKx89"
   },
   "outputs": [],
   "source": [
    "df = pd.read_sql_query(\"select * from comment_new\", get_connection())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 930,
     "status": "ok",
     "timestamp": 1546060771940,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "gNzprxGqZyay",
    "outputId": "4fb0577e-d940-4ceb-e489-e8382ff882ba"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(289204, 9)"
      ]
     },
     "execution_count": 31,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 80
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 823,
     "status": "ok",
     "timestamp": 1546060653221,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "uUmhyO2MXAHj",
    "outputId": "2845d460-cfce-4ef9-9234-ee5319bf6017"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>TIME</th>\n",
       "      <th>MOVIEID</th>\n",
       "      <th>RATING</th>\n",
       "      <th>CONTENT</th>\n",
       "      <th>CREATOR</th>\n",
       "      <th>ADD_TIME</th>\n",
       "      <th>NEWDATA</th>\n",
       "      <th>USERID</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10000</td>\n",
       "      <td>2015-10-09 20:02:19</td>\n",
       "      <td>10533913</td>\n",
       "      <td>4</td>\n",
       "      <td>虽然依然充满了想象力，但突然觉得这部很一般呢。</td>\n",
       "      <td>妖怪dodo</td>\n",
       "      <td>2018-01-05 15:23:18</td>\n",
       "      <td>0</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      ID                 TIME   MOVIEID RATING                  CONTENT  \\\n",
       "0  10000  2015-10-09 20:02:19  10533913      4  虽然依然充满了想象力，但突然觉得这部很一般呢。   \n",
       "\n",
       "  CREATOR             ADD_TIME NEWDATA                            USERID  \n",
       "0  妖怪dodo  2018-01-05 15:23:18       0  cf2349f9c01f9a5cd4050aebd30ab74f  "
      ]
     },
     "execution_count": 28,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "5ndb0jAEZV8O"
   },
   "outputs": [],
   "source": [
    "df_incremental = pd.read_sql_query(\"select * from comment_new where newdata=2\", get_connection())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 795,
     "status": "ok",
     "timestamp": 1546062997362,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "a1zEDkhoZty-",
    "outputId": "d4432f86-5f5b-48ee-8e53-abf91d971ad0"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 9)"
      ]
     },
     "execution_count": 50,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_incremental.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 80
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 718,
     "status": "ok",
     "timestamp": 1546062999553,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "8vzZT2Afb5aY",
    "outputId": "e9bf6e6e-8c53-4c18-edb1-07531c4c1b03"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>TIME</th>\n",
       "      <th>MOVIEID</th>\n",
       "      <th>RATING</th>\n",
       "      <th>CONTENT</th>\n",
       "      <th>CREATOR</th>\n",
       "      <th>ADD_TIME</th>\n",
       "      <th>NEWDATA</th>\n",
       "      <th>USERID</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>300004</td>\n",
       "      <td>2018-12-29 13:09:21</td>\n",
       "      <td>1296384</td>\n",
       "      <td>4</td>\n",
       "      <td>中等</td>\n",
       "      <td>wuenda</td>\n",
       "      <td>2018-12-29 13:09:21</td>\n",
       "      <td>2</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       ID                 TIME  MOVIEID RATING CONTENT CREATOR  \\\n",
       "0  300004  2018-12-29 13:09:21  1296384      4      中等  wuenda   \n",
       "\n",
       "              ADD_TIME NEWDATA                            USERID  \n",
       "0  2018-12-29 13:09:21       2  cf2349f9c01f9a5cd4050aebd30ab74f  "
      ]
     },
     "execution_count": 51,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_incremental.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 111
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 503,
     "status": "ok",
     "timestamp": 1546062999868,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "BCbnOG7ocFn2",
    "outputId": "993f5c4f-4cec-43ad-93b3-461a7ac68b0a"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>TIME</th>\n",
       "      <th>MOVIEID</th>\n",
       "      <th>RATING</th>\n",
       "      <th>CONTENT</th>\n",
       "      <th>CREATOR</th>\n",
       "      <th>ADD_TIME</th>\n",
       "      <th>NEWDATA</th>\n",
       "      <th>USERID</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>289202</th>\n",
       "      <td>99998</td>\n",
       "      <td>2007-03-17 12:23:49</td>\n",
       "      <td>1294829</td>\n",
       "      <td>2</td>\n",
       "      <td>Jay Roach</td>\n",
       "      <td>维超</td>\n",
       "      <td>2018-01-19 16:16:00</td>\n",
       "      <td>0</td>\n",
       "      <td>57644954ca89054fe1ae07f2730affff</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>289203</th>\n",
       "      <td>99999</td>\n",
       "      <td>2011-06-26 21:43:38</td>\n",
       "      <td>1294829</td>\n",
       "      <td>2</td>\n",
       "      <td>无敌滥。。</td>\n",
       "      <td>大士かっこいい</td>\n",
       "      <td>2018-01-19 16:16:00</td>\n",
       "      <td>0</td>\n",
       "      <td>ca306783cb48666f1dc7c72a8d8f6e53</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           ID                 TIME  MOVIEID RATING    CONTENT  CREATOR  \\\n",
       "289202  99998  2007-03-17 12:23:49  1294829      2  Jay Roach       维超   \n",
       "289203  99999  2011-06-26 21:43:38  1294829      2      无敌滥。。  大士かっこいい   \n",
       "\n",
       "                   ADD_TIME NEWDATA                            USERID  \n",
       "289202  2018-01-19 16:16:00       0  57644954ca89054fe1ae07f2730affff  \n",
       "289203  2018-01-19 16:16:00       0  ca306783cb48666f1dc7c72a8d8f6e53  "
      ]
     },
     "execution_count": 52,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "t_U8ZjP7cH1O"
   },
   "outputs": [],
   "source": [
    "df_new = df.append(df_incremental)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 713,
     "status": "ok",
     "timestamp": 1546063003477,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "xhqtojlCcZRC",
    "outputId": "c13e1a39-97da-414c-b8b4-6d9fc74a8ecd"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(289205, 9)"
      ]
     },
     "execution_count": 54,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_new.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 111
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 749,
     "status": "ok",
     "timestamp": 1546061483631,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "kv9l5lk8cfxx",
    "outputId": "4993d665-7f34-4b0b-fe4c-48e380ec0d27"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>TIME</th>\n",
       "      <th>MOVIEID</th>\n",
       "      <th>RATING</th>\n",
       "      <th>CONTENT</th>\n",
       "      <th>CREATOR</th>\n",
       "      <th>ADD_TIME</th>\n",
       "      <th>NEWDATA</th>\n",
       "      <th>USERID</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>289203</th>\n",
       "      <td>99999</td>\n",
       "      <td>2011-06-26 21:43:38</td>\n",
       "      <td>1294829</td>\n",
       "      <td>2</td>\n",
       "      <td>无敌滥。。</td>\n",
       "      <td>大士かっこいい</td>\n",
       "      <td>2018-01-19 16:16:00</td>\n",
       "      <td>0</td>\n",
       "      <td>ca306783cb48666f1dc7c72a8d8f6e53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>300004</td>\n",
       "      <td>2018-12-29 13:09:21</td>\n",
       "      <td>1296384</td>\n",
       "      <td>4</td>\n",
       "      <td>中等</td>\n",
       "      <td>wuenda</td>\n",
       "      <td>2018-12-29 13:09:21</td>\n",
       "      <td>1</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            ID                 TIME  MOVIEID RATING CONTENT  CREATOR  \\\n",
       "289203   99999  2011-06-26 21:43:38  1294829      2   无敌滥。。  大士かっこいい   \n",
       "0       300004  2018-12-29 13:09:21  1296384      4      中等   wuenda   \n",
       "\n",
       "                   ADD_TIME NEWDATA                            USERID  \n",
       "289203  2018-01-19 16:16:00       0  ca306783cb48666f1dc7c72a8d8f6e53  \n",
       "0       2018-12-29 13:09:21       1  cf2349f9c01f9a5cd4050aebd30ab74f  "
      ]
     },
     "execution_count": 48,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_new.tail(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 255
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 905,
     "status": "ok",
     "timestamp": 1545737266956,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "kW1bngOcK4DF",
    "outputId": "dc323b5e-36b9-4835-f415-f1331f7f14cc"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>TIME</th>\n",
       "      <th>MOVIEID</th>\n",
       "      <th>RATING</th>\n",
       "      <th>CONTENT</th>\n",
       "      <th>CREATOR</th>\n",
       "      <th>ADD_TIME</th>\n",
       "      <th>NEWDATA</th>\n",
       "      <th>USERID</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10000</td>\n",
       "      <td>2015-10-09 20:02:19</td>\n",
       "      <td>10533913</td>\n",
       "      <td>4</td>\n",
       "      <td>虽然依然充满了想象力，但突然觉得这部很一般呢。</td>\n",
       "      <td>妖怪dodo</td>\n",
       "      <td>2018-01-05 15:23:18</td>\n",
       "      <td>0</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100000</td>\n",
       "      <td>2011-09-06 00:27:27</td>\n",
       "      <td>1294829</td>\n",
       "      <td>2</td>\n",
       "      <td>小肚鸡肠。</td>\n",
       "      <td>Dexter</td>\n",
       "      <td>2018-01-19 16:16:00</td>\n",
       "      <td>0</td>\n",
       "      <td>6abe55491bf68a3873106a1945ad631e</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100001</td>\n",
       "      <td>2011-07-12 15:45:36</td>\n",
       "      <td>1294829</td>\n",
       "      <td>2</td>\n",
       "      <td>枉费了我的1.82G!!!</td>\n",
       "      <td>Ca B.</td>\n",
       "      <td>2018-01-19 16:16:00</td>\n",
       "      <td>0</td>\n",
       "      <td>4092d171faf4e2bcdfb9c6fc230fc594</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100002</td>\n",
       "      <td>2012-02-18 10:21:04</td>\n",
       "      <td>1294829</td>\n",
       "      <td>2</td>\n",
       "      <td>轻喜剧，i'm really on your team</td>\n",
       "      <td>小man</td>\n",
       "      <td>2018-01-19 16:16:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0d295b2e85b5a47dd7c0d74176153598</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>100003</td>\n",
       "      <td>2010-04-17 01:21:24</td>\n",
       "      <td>1294829</td>\n",
       "      <td>2</td>\n",
       "      <td>德尼罗为什么会接这剧本？？？就因为没演过傻叉？</td>\n",
       "      <td>serenity never</td>\n",
       "      <td>2018-01-19 16:16:00</td>\n",
       "      <td>0</td>\n",
       "      <td>536a5ea5ea7a5a4259a7c2c2082301ab</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       ID                 TIME   MOVIEID RATING                      CONTENT  \\\n",
       "0   10000  2015-10-09 20:02:19  10533913      4      虽然依然充满了想象力，但突然觉得这部很一般呢。   \n",
       "1  100000  2011-09-06 00:27:27   1294829      2                        小肚鸡肠。   \n",
       "2  100001  2011-07-12 15:45:36   1294829      2                枉费了我的1.82G!!!   \n",
       "3  100002  2012-02-18 10:21:04   1294829      2  轻喜剧，i'm really on your team   \n",
       "4  100003  2010-04-17 01:21:24   1294829      2      德尼罗为什么会接这剧本？？？就因为没演过傻叉？   \n",
       "\n",
       "          CREATOR             ADD_TIME NEWDATA  \\\n",
       "0          妖怪dodo  2018-01-05 15:23:18       0   \n",
       "1          Dexter  2018-01-19 16:16:00       0   \n",
       "2           Ca B.  2018-01-19 16:16:00       0   \n",
       "3            小man  2018-01-19 16:16:00       0   \n",
       "4  serenity never  2018-01-19 16:16:00       0   \n",
       "\n",
       "                             USERID  \n",
       "0  cf2349f9c01f9a5cd4050aebd30ab74f  \n",
       "1  6abe55491bf68a3873106a1945ad631e  \n",
       "2  4092d171faf4e2bcdfb9c6fc230fc594  \n",
       "3  0d295b2e85b5a47dd7c0d74176153598  \n",
       "4  536a5ea5ea7a5a4259a7c2c2082301ab  "
      ]
     },
     "execution_count": 6,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 870,
     "status": "ok",
     "timestamp": 1545737269493,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "daVuWoUxK7I0",
    "outputId": "7cb9adbb-07ec-49dd-b9a6-976b6a1bed20"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(289202, 9)"
      ]
     },
     "execution_count": 7,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "gwFKuHCOaMrF"
   },
   "outputs": [],
   "source": [
    "df_movie = pd.read_sql_query(\"select * from movie\", get_connection())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 932,
     "status": "ok",
     "timestamp": 1545737352306,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "qLV2PQ4Vagtu",
    "outputId": "df018258-bb62-4307-f3a7-a1384b2e313c"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(6629, 12)"
      ]
     },
     "execution_count": 9,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_movie.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 289
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 836,
     "status": "ok",
     "timestamp": 1545737356036,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "tIwVQQRXaicU",
    "outputId": "5268cb45-2f22-4104-c59f-a8092d489d84"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>ADD_TIME</th>\n",
       "      <th>type</th>\n",
       "      <th>actors</th>\n",
       "      <th>region</th>\n",
       "      <th>director</th>\n",
       "      <th>trait</th>\n",
       "      <th>rat</th>\n",
       "      <th>enable</th>\n",
       "      <th>description</th>\n",
       "      <th>img</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10001432</td>\n",
       "      <td>颠倒的帕特玛</td>\n",
       "      <td>2018-02-07 20:46:08</td>\n",
       "      <td>剧情|冒险|科幻|爱情</td>\n",
       "      <td>藤井雪代|冈本信彦|大畑伸太郎|福松进纱|加藤将之</td>\n",
       "      <td>日本</td>\n",
       "      <td>吉浦康裕</td>\n",
       "      <td>青春</td>\n",
       "      <td>7.9</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10047547</td>\n",
       "      <td>饥饿游戏3：嘲笑鸟(下)</td>\n",
       "      <td>2018-02-07 20:27:08</td>\n",
       "      <td>奇幻|惊悚|爱情|战争|剧情|科幻|冒险|动作</td>\n",
       "      <td>詹妮弗·劳伦斯|乔什·哈切森|利亚姆·海姆斯沃斯|伍迪·哈里森|伊丽莎白·班克斯</td>\n",
       "      <td>美国</td>\n",
       "      <td>弗朗西斯·劳伦斯</td>\n",
       "      <td>青春</td>\n",
       "      <td>6.2</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10342838</td>\n",
       "      <td>弯刀杀戮</td>\n",
       "      <td>2018-02-07 20:42:15</td>\n",
       "      <td>喜剧|犯罪|惊悚|动作</td>\n",
       "      <td>丹尼·特雷霍|米歇尔·罗德里格兹|索菲娅·维加拉|艾梅柏·希尔德|Lady Gaga</td>\n",
       "      <td>俄罗斯</td>\n",
       "      <td>罗伯特·罗德里格兹</td>\n",
       "      <td>搞笑</td>\n",
       "      <td>5.7</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10355329</td>\n",
       "      <td>巴菲的奇妙命运</td>\n",
       "      <td>2018-02-07 20:44:01</td>\n",
       "      <td>剧情|喜剧|音乐|爱情</td>\n",
       "      <td>佩丽冉卡·曹帕拉|兰比尔·卡普尔|伊利亚娜·狄克鲁兹|Akash Khurana|沙鲁巴·舒克拉</td>\n",
       "      <td>印度</td>\n",
       "      <td>阿努拉格·巴苏</td>\n",
       "      <td>感人|经典|励志|搞笑|文艺</td>\n",
       "      <td>8.3</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10428476</td>\n",
       "      <td>小屁孩日记3</td>\n",
       "      <td>2018-02-07 20:47:00</td>\n",
       "      <td>剧情|喜剧</td>\n",
       "      <td>扎克瑞·戈登|瑞秋·哈里斯|戴文·博斯蒂克|罗伯特·卡普荣|佩顿·李斯特</td>\n",
       "      <td>加拿大</td>\n",
       "      <td>大卫·博维斯</td>\n",
       "      <td>青春|搞笑</td>\n",
       "      <td>6.7</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         id          name             ADD_TIME                     type  \\\n",
       "0  10001432        颠倒的帕特玛  2018-02-07 20:46:08              剧情|冒险|科幻|爱情   \n",
       "1  10047547  饥饿游戏3：嘲笑鸟(下)  2018-02-07 20:27:08  奇幻|惊悚|爱情|战争|剧情|科幻|冒险|动作   \n",
       "2  10342838          弯刀杀戮  2018-02-07 20:42:15              喜剧|犯罪|惊悚|动作   \n",
       "3  10355329       巴菲的奇妙命运  2018-02-07 20:44:01              剧情|喜剧|音乐|爱情   \n",
       "4  10428476        小屁孩日记3  2018-02-07 20:47:00                    剧情|喜剧   \n",
       "\n",
       "                                             actors region   director  \\\n",
       "0                         藤井雪代|冈本信彦|大畑伸太郎|福松进纱|加藤将之     日本       吉浦康裕   \n",
       "1          詹妮弗·劳伦斯|乔什·哈切森|利亚姆·海姆斯沃斯|伍迪·哈里森|伊丽莎白·班克斯     美国   弗朗西斯·劳伦斯   \n",
       "2        丹尼·特雷霍|米歇尔·罗德里格兹|索菲娅·维加拉|艾梅柏·希尔德|Lady Gaga    俄罗斯  罗伯特·罗德里格兹   \n",
       "3  佩丽冉卡·曹帕拉|兰比尔·卡普尔|伊利亚娜·狄克鲁兹|Akash Khurana|沙鲁巴·舒克拉     印度    阿努拉格·巴苏   \n",
       "4              扎克瑞·戈登|瑞秋·哈里斯|戴文·博斯蒂克|罗伯特·卡普荣|佩顿·李斯特    加拿大     大卫·博维斯   \n",
       "\n",
       "            trait  rat enable description img  \n",
       "0              青春  7.9      1                  \n",
       "1              青春  6.2      1                  \n",
       "2              搞笑  5.7      1                  \n",
       "3  感人|经典|励志|搞笑|文艺  8.3      1                  \n",
       "4           青春|搞笑  6.7      1                  "
      ]
     },
     "execution_count": 10,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_movie.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "znnG2EDAajfS"
   },
   "outputs": [],
   "source": [
    "df_user_pro = pd.read_sql_query(\"select * from userproex_new\", get_connection())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 1058,
     "status": "ok",
     "timestamp": 1545737428236,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "hRpLtloFbhF6",
    "outputId": "7c8328c6-d7f3-4703-9400-0a42b7d37ac8"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(73487, 7)"
      ]
     },
     "execution_count": 12,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_user_pro.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 204
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 1060,
     "status": "ok",
     "timestamp": 1545737431819,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "f_DlgzmabigU",
    "outputId": "98f1078c-7d86-49a8-f0e7-9b1e3894a388"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>userid</th>\n",
       "      <th>rmax</th>\n",
       "      <th>rmin</th>\n",
       "      <th>ravg</th>\n",
       "      <th>rcount</th>\n",
       "      <th>rsum</th>\n",
       "      <th>rmedian</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>00000bc601790de1bafd1914e2cd9abb</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>00014d0eec614e33a18439f38a97ab5e</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0002645703e1980557d3d5b1d50e5a71</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.000</td>\n",
       "      <td>4.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0002e81335b6278111bf5e2691934361</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0004823fea6f2c16b312c56c95c9689e</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.125</td>\n",
       "      <td>8.0</td>\n",
       "      <td>33.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             userid  rmax  rmin   ravg  rcount  rsum  rmedian\n",
       "0  00000bc601790de1bafd1914e2cd9abb   2.0   2.0  2.000     1.0   2.0      2.0\n",
       "1  00014d0eec614e33a18439f38a97ab5e   2.0   2.0  2.000     1.0   2.0      2.0\n",
       "2  0002645703e1980557d3d5b1d50e5a71   5.0   2.0  4.000     4.0  16.0      4.5\n",
       "3  0002e81335b6278111bf5e2691934361   2.0   2.0  2.000     1.0   2.0      2.0\n",
       "4  0004823fea6f2c16b312c56c95c9689e   5.0   2.0  4.125     8.0  33.0      4.0"
      ]
     },
     "execution_count": 13,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_user_pro.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "HH5AA8MYbj0L"
   },
   "outputs": [],
   "source": [
    "df_head = df.head(1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "IWpQPpxCb9FJ"
   },
   "outputs": [],
   "source": [
    "df_movie_head = df_movie.head(1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "3bUsgRBsb_Q7"
   },
   "outputs": [],
   "source": [
    "df_user_head = df_user_pro.head(1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "O0YiEpEIcDWK"
   },
   "outputs": [],
   "source": [
    "df_data_head = pd.merge(df_head, df_movie_head, left_on=['MOVIEID'], right_on=['id'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1052
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 936,
     "status": "ok",
     "timestamp": 1545737434809,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "YxHzb16deFP7",
    "outputId": "b53923c3-e728-47e1-f092-2f3fd900a9bb"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>TIME</th>\n",
       "      <th>MOVIEID</th>\n",
       "      <th>RATING</th>\n",
       "      <th>CONTENT</th>\n",
       "      <th>CREATOR</th>\n",
       "      <th>ADD_TIME_x</th>\n",
       "      <th>NEWDATA</th>\n",
       "      <th>USERID</th>\n",
       "      <th>id</th>\n",
       "      <th>...</th>\n",
       "      <th>ADD_TIME_y</th>\n",
       "      <th>type</th>\n",
       "      <th>actors</th>\n",
       "      <th>region</th>\n",
       "      <th>director</th>\n",
       "      <th>trait</th>\n",
       "      <th>rat</th>\n",
       "      <th>enable</th>\n",
       "      <th>description</th>\n",
       "      <th>img</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10000</td>\n",
       "      <td>2015-10-09 20:02:19</td>\n",
       "      <td>10533913</td>\n",
       "      <td>4</td>\n",
       "      <td>虽然依然充满了想象力，但突然觉得这部很一般呢。</td>\n",
       "      <td>妖怪dodo</td>\n",
       "      <td>2018-01-05 15:23:18</td>\n",
       "      <td>0</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "      <td>10533913</td>\n",
       "      <td>...</td>\n",
       "      <td>Fri Jan  5 11:35:19 2018</td>\n",
       "      <td>剧情|奇幻|冒险|喜剧</td>\n",
       "      <td>艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克</td>\n",
       "      <td>美国</td>\n",
       "      <td>彼特·道格特|罗纳尔多·德尔·卡门</td>\n",
       "      <td>感人|经典|励志</td>\n",
       "      <td>8.7</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10001</td>\n",
       "      <td>2015-12-01 22:44:41</td>\n",
       "      <td>10533913</td>\n",
       "      <td>4</td>\n",
       "      <td>颇有心理分析的味道，讲了一个关于成长和家庭的故事。</td>\n",
       "      <td>Robert</td>\n",
       "      <td>2018-01-05 15:23:18</td>\n",
       "      <td>0</td>\n",
       "      <td>4ffe35db90d94c6041fb8ddf7b44df29</td>\n",
       "      <td>10533913</td>\n",
       "      <td>...</td>\n",
       "      <td>Fri Jan  5 11:35:19 2018</td>\n",
       "      <td>剧情|奇幻|冒险|喜剧</td>\n",
       "      <td>艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克</td>\n",
       "      <td>美国</td>\n",
       "      <td>彼特·道格特|罗纳尔多·德尔·卡门</td>\n",
       "      <td>感人|经典|励志</td>\n",
       "      <td>8.7</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10002</td>\n",
       "      <td>2016-03-01 22:01:22</td>\n",
       "      <td>10533913</td>\n",
       "      <td>5</td>\n",
       "      <td>冰棒出场退场都哭惨我了</td>\n",
       "      <td>有怪受有怪受有怪受.</td>\n",
       "      <td>2018-01-05 15:23:18</td>\n",
       "      <td>0</td>\n",
       "      <td>7a9ba2e320c754b8bb023fa2023e7ed0</td>\n",
       "      <td>10533913</td>\n",
       "      <td>...</td>\n",
       "      <td>Fri Jan  5 11:35:19 2018</td>\n",
       "      <td>剧情|奇幻|冒险|喜剧</td>\n",
       "      <td>艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克</td>\n",
       "      <td>美国</td>\n",
       "      <td>彼特·道格特|罗纳尔多·德尔·卡门</td>\n",
       "      <td>感人|经典|励志</td>\n",
       "      <td>8.7</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10003</td>\n",
       "      <td>2016-02-28 22:27:54</td>\n",
       "      <td>10533913</td>\n",
       "      <td>4</td>\n",
       "      <td>这种想象力，得用最强大脑来自圆其说，这个层面上，做的相当不错了</td>\n",
       "      <td>seamouse</td>\n",
       "      <td>2018-01-05 15:23:18</td>\n",
       "      <td>0</td>\n",
       "      <td>422f5fddfea5db02ce76ca885818cad0</td>\n",
       "      <td>10533913</td>\n",
       "      <td>...</td>\n",
       "      <td>Fri Jan  5 11:35:19 2018</td>\n",
       "      <td>剧情|奇幻|冒险|喜剧</td>\n",
       "      <td>艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克</td>\n",
       "      <td>美国</td>\n",
       "      <td>彼特·道格特|罗纳尔多·德尔·卡门</td>\n",
       "      <td>感人|经典|励志</td>\n",
       "      <td>8.7</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10004</td>\n",
       "      <td>2015-10-06 19:19:15</td>\n",
       "      <td>10533913</td>\n",
       "      <td>5</td>\n",
       "      <td>电影的每一个细节都与丰富的想象力紧紧联系在一起，实在是太喜欢Joy，看看看，欢乐活力、不屈不...</td>\n",
       "      <td>翠墨待书</td>\n",
       "      <td>2018-01-05 15:23:22</td>\n",
       "      <td>0</td>\n",
       "      <td>3ce13d06ddbc80d5cce2143b1fb69b71</td>\n",
       "      <td>10533913</td>\n",
       "      <td>...</td>\n",
       "      <td>Fri Jan  5 11:35:19 2018</td>\n",
       "      <td>剧情|奇幻|冒险|喜剧</td>\n",
       "      <td>艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克</td>\n",
       "      <td>美国</td>\n",
       "      <td>彼特·道格特|罗纳尔多·德尔·卡门</td>\n",
       "      <td>感人|经典|励志</td>\n",
       "      <td>8.7</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      ID                 TIME   MOVIEID RATING  \\\n",
       "0  10000  2015-10-09 20:02:19  10533913      4   \n",
       "1  10001  2015-12-01 22:44:41  10533913      4   \n",
       "2  10002  2016-03-01 22:01:22  10533913      5   \n",
       "3  10003  2016-02-28 22:27:54  10533913      4   \n",
       "4  10004  2015-10-06 19:19:15  10533913      5   \n",
       "\n",
       "                                             CONTENT     CREATOR  \\\n",
       "0                            虽然依然充满了想象力，但突然觉得这部很一般呢。      妖怪dodo   \n",
       "1                          颇有心理分析的味道，讲了一个关于成长和家庭的故事。      Robert   \n",
       "2                                        冰棒出场退场都哭惨我了  有怪受有怪受有怪受.   \n",
       "3                    这种想象力，得用最强大脑来自圆其说，这个层面上，做的相当不错了    seamouse   \n",
       "4  电影的每一个细节都与丰富的想象力紧紧联系在一起，实在是太喜欢Joy，看看看，欢乐活力、不屈不...        翠墨待书   \n",
       "\n",
       "            ADD_TIME_x NEWDATA                            USERID        id  \\\n",
       "0  2018-01-05 15:23:18       0  cf2349f9c01f9a5cd4050aebd30ab74f  10533913   \n",
       "1  2018-01-05 15:23:18       0  4ffe35db90d94c6041fb8ddf7b44df29  10533913   \n",
       "2  2018-01-05 15:23:18       0  7a9ba2e320c754b8bb023fa2023e7ed0  10533913   \n",
       "3  2018-01-05 15:23:18       0  422f5fddfea5db02ce76ca885818cad0  10533913   \n",
       "4  2018-01-05 15:23:22       0  3ce13d06ddbc80d5cce2143b1fb69b71  10533913   \n",
       "\n",
       "  ...                ADD_TIME_y         type  \\\n",
       "0 ...  Fri Jan  5 11:35:19 2018  剧情|奇幻|冒险|喜剧   \n",
       "1 ...  Fri Jan  5 11:35:19 2018  剧情|奇幻|冒险|喜剧   \n",
       "2 ...  Fri Jan  5 11:35:19 2018  剧情|奇幻|冒险|喜剧   \n",
       "3 ...  Fri Jan  5 11:35:19 2018  剧情|奇幻|冒险|喜剧   \n",
       "4 ...  Fri Jan  5 11:35:19 2018  剧情|奇幻|冒险|喜剧   \n",
       "\n",
       "                                actors region           director     trait  \\\n",
       "0  艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克     美国  彼特·道格特|罗纳尔多·德尔·卡门  感人|经典|励志   \n",
       "1  艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克     美国  彼特·道格特|罗纳尔多·德尔·卡门  感人|经典|励志   \n",
       "2  艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克     美国  彼特·道格特|罗纳尔多·德尔·卡门  感人|经典|励志   \n",
       "3  艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克     美国  彼特·道格特|罗纳尔多·德尔·卡门  感人|经典|励志   \n",
       "4  艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克     美国  彼特·道格特|罗纳尔多·德尔·卡门  感人|经典|励志   \n",
       "\n",
       "   rat enable description img  \n",
       "0  8.7      1                  \n",
       "1  8.7      1                  \n",
       "2  8.7      1                  \n",
       "3  8.7      1                  \n",
       "4  8.7      1                  \n",
       "\n",
       "[5 rows x 21 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data_head.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "U2ylpYbYeGeZ"
   },
   "outputs": [],
   "source": [
    "df_data_head = pd.merge(df_data_head, df_user_head, left_on=['USERID'], right_on=['userid'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 840,
     "status": "ok",
     "timestamp": 1545737437861,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "gYQgXIfdgILg",
    "outputId": "a2fb4c73-2f9a-4361-a928-aecdd4ceff3e"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(15, 28)"
      ]
     },
     "execution_count": 20,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data_head.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 763
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 901,
     "status": "ok",
     "timestamp": 1545737441048,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "IT44HA8SgM2R",
    "outputId": "3d2152a7-31ce-4c25-c06e-7d96e1ed5779"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>TIME</th>\n",
       "      <th>MOVIEID</th>\n",
       "      <th>RATING</th>\n",
       "      <th>CONTENT</th>\n",
       "      <th>CREATOR</th>\n",
       "      <th>ADD_TIME_x</th>\n",
       "      <th>NEWDATA</th>\n",
       "      <th>USERID</th>\n",
       "      <th>id</th>\n",
       "      <th>...</th>\n",
       "      <th>enable</th>\n",
       "      <th>description</th>\n",
       "      <th>img</th>\n",
       "      <th>userid</th>\n",
       "      <th>rmax</th>\n",
       "      <th>rmin</th>\n",
       "      <th>ravg</th>\n",
       "      <th>rcount</th>\n",
       "      <th>rsum</th>\n",
       "      <th>rmedian</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10032</td>\n",
       "      <td>2016-03-22 02:42:17</td>\n",
       "      <td>10533913</td>\n",
       "      <td>5</td>\n",
       "      <td>看到莱利看到爸妈的笑脸，产生了第一个黄色（Joy）的记忆，慢慢累积了金黄色的童年，莫名地哭了...</td>\n",
       "      <td>玄子</td>\n",
       "      <td>2018-01-05 15:23:24</td>\n",
       "      <td>0</td>\n",
       "      <td>0082b8bf7f72277701efb2cc4c48cb09</td>\n",
       "      <td>10533913</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>0082b8bf7f72277701efb2cc4c48cb09</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.00000</td>\n",
       "      <td>4.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10049</td>\n",
       "      <td>2015-12-21 09:23:35</td>\n",
       "      <td>10533913</td>\n",
       "      <td>4</td>\n",
       "      <td>剧情紧凑，制作精良，一些小细节挺有意思</td>\n",
       "      <td>Prague Night</td>\n",
       "      <td>2018-01-05 15:23:28</td>\n",
       "      <td>0</td>\n",
       "      <td>00e5c112c9fcbeac66738719e2760573</td>\n",
       "      <td>10533913</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>00e5c112c9fcbeac66738719e2760573</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.87500</td>\n",
       "      <td>16.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100032</td>\n",
       "      <td>2015-06-15 13:22:18</td>\n",
       "      <td>1294829</td>\n",
       "      <td>2</td>\n",
       "      <td>是不是每个岳父对女婿，就像婆婆对媳妇，永远就是充满敌意~不过真心没觉得那么经典，为啥评分这么...</td>\n",
       "      <td>Ivan</td>\n",
       "      <td>2018-01-19 16:16:04</td>\n",
       "      <td>0</td>\n",
       "      <td>036e3491ba499df64611c82b6bcdd37d</td>\n",
       "      <td>1294829</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>036e3491ba499df64611c82b6bcdd37d</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.23529</td>\n",
       "      <td>136.0</td>\n",
       "      <td>576.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100036</td>\n",
       "      <td>2012-03-29 14:25:58</td>\n",
       "      <td>1294829</td>\n",
       "      <td>2</td>\n",
       "      <td>挺无聊的，男猪脚蛮帅。</td>\n",
       "      <td>Ｌ°</td>\n",
       "      <td>2018-01-19 16:16:04</td>\n",
       "      <td>0</td>\n",
       "      <td>02b474f4d8c9d99b82ff5fe937dccef2</td>\n",
       "      <td>1294829</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>02b474f4d8c9d99b82ff5fe937dccef2</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.00000</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>100049</td>\n",
       "      <td>2012-03-29 14:25:58</td>\n",
       "      <td>1294829</td>\n",
       "      <td>2</td>\n",
       "      <td>挺无聊的，男猪脚蛮帅。</td>\n",
       "      <td>Ｌ°</td>\n",
       "      <td>2018-01-19 16:16:05</td>\n",
       "      <td>0</td>\n",
       "      <td>02b474f4d8c9d99b82ff5fe937dccef2</td>\n",
       "      <td>1294829</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>02b474f4d8c9d99b82ff5fe937dccef2</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.00000</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 28 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       ID                 TIME   MOVIEID RATING  \\\n",
       "0   10032  2016-03-22 02:42:17  10533913      5   \n",
       "1   10049  2015-12-21 09:23:35  10533913      4   \n",
       "2  100032  2015-06-15 13:22:18   1294829      2   \n",
       "3  100036  2012-03-29 14:25:58   1294829      2   \n",
       "4  100049  2012-03-29 14:25:58   1294829      2   \n",
       "\n",
       "                                             CONTENT       CREATOR  \\\n",
       "0  看到莱利看到爸妈的笑脸，产生了第一个黄色（Joy）的记忆，慢慢累积了金黄色的童年，莫名地哭了...            玄子   \n",
       "1                                剧情紧凑，制作精良，一些小细节挺有意思  Prague Night   \n",
       "2  是不是每个岳父对女婿，就像婆婆对媳妇，永远就是充满敌意~不过真心没觉得那么经典，为啥评分这么...          Ivan   \n",
       "3                                        挺无聊的，男猪脚蛮帅。            Ｌ°   \n",
       "4                                        挺无聊的，男猪脚蛮帅。            Ｌ°   \n",
       "\n",
       "            ADD_TIME_x NEWDATA                            USERID        id  \\\n",
       "0  2018-01-05 15:23:24       0  0082b8bf7f72277701efb2cc4c48cb09  10533913   \n",
       "1  2018-01-05 15:23:28       0  00e5c112c9fcbeac66738719e2760573  10533913   \n",
       "2  2018-01-19 16:16:04       0  036e3491ba499df64611c82b6bcdd37d   1294829   \n",
       "3  2018-01-19 16:16:04       0  02b474f4d8c9d99b82ff5fe937dccef2   1294829   \n",
       "4  2018-01-19 16:16:05       0  02b474f4d8c9d99b82ff5fe937dccef2   1294829   \n",
       "\n",
       "    ...   enable description img                            userid rmax rmin  \\\n",
       "0   ...        1                  0082b8bf7f72277701efb2cc4c48cb09  5.0  2.0   \n",
       "1   ...        1                  00e5c112c9fcbeac66738719e2760573  5.0  2.0   \n",
       "2   ...        1                  036e3491ba499df64611c82b6bcdd37d  5.0  1.0   \n",
       "3   ...        1                  02b474f4d8c9d99b82ff5fe937dccef2  2.0  2.0   \n",
       "4   ...        1                  02b474f4d8c9d99b82ff5fe937dccef2  2.0  2.0   \n",
       "\n",
       "      ravg rcount   rsum rmedian  \n",
       "0  4.00000    4.0   16.0     4.5  \n",
       "1  3.87500   16.0   62.0     4.0  \n",
       "2  4.23529  136.0  576.0     4.0  \n",
       "3  2.00000    2.0    4.0     2.0  \n",
       "4  2.00000    2.0    4.0     2.0  \n",
       "\n",
       "[5 rows x 28 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data_head.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "rd_VwKglgQVH"
   },
   "outputs": [],
   "source": [
    "df_data = pd.merge(df, df_movie, left_on=['MOVIEID'], right_on=['id'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "Ju6Oap6rguzX"
   },
   "outputs": [],
   "source": [
    "df_data = pd.merge(df_data, df_user_pro, left_on=['USERID'], right_on=['userid'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 808,
     "status": "ok",
     "timestamp": 1545737446335,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "7w1KZ6rYg1_P",
    "outputId": "067b2705-50ed-4a38-81f1-7a0f35b1b7f5"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(289192, 28)"
      ]
     },
     "execution_count": 24,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 988
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 911,
     "status": "ok",
     "timestamp": 1545737448634,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "897VlHCYgx4u",
    "outputId": "e01dfeac-8895-4bbf-d030-8f16408a1e48"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <td>10000</td>\n",
       "      <td>100231</td>\n",
       "      <td>205834</td>\n",
       "      <td>221461</td>\n",
       "      <td>225496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TIME</th>\n",
       "      <td>2015-10-09 20:02:19</td>\n",
       "      <td>2009-01-31 22:36:03</td>\n",
       "      <td>2016-11-25 17:19:18</td>\n",
       "      <td>2016-01-03 09:56:48</td>\n",
       "      <td>2016-03-20 22:54:09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MOVIEID</th>\n",
       "      <td>10533913</td>\n",
       "      <td>1294829</td>\n",
       "      <td>22939161</td>\n",
       "      <td>25864085</td>\n",
       "      <td>26303622</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RATING</th>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CONTENT</th>\n",
       "      <td>虽然依然充满了想象力，但突然觉得这部很一般呢。</td>\n",
       "      <td>开头很好听～～a fool in love</td>\n",
       "      <td>特别没意思了。</td>\n",
       "      <td>虽然也是浩瀚宇宙，但跟诺兰想要传达的完全不一样。全片证明了一个论题：学好数理化，走遍宇宙都不...</td>\n",
       "      <td>不寒而栗</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CREATOR</th>\n",
       "      <td>妖怪dodo</td>\n",
       "      <td>妖怪dodo</td>\n",
       "      <td>妖怪dodo</td>\n",
       "      <td>妖怪dodo</td>\n",
       "      <td>妖怪dodo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ADD_TIME_x</th>\n",
       "      <td>2018-01-05 15:23:18</td>\n",
       "      <td>2018-01-19 16:16:23</td>\n",
       "      <td>2018-01-25 13:44:26</td>\n",
       "      <td>2018-01-25 15:55:03</td>\n",
       "      <td>2018-01-25 16:18:51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NEWDATA</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>USERID</th>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>id</th>\n",
       "      <td>10533913</td>\n",
       "      <td>1294829</td>\n",
       "      <td>22939161</td>\n",
       "      <td>25864085</td>\n",
       "      <td>26303622</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>name</th>\n",
       "      <td>头脑特工队</td>\n",
       "      <td>拜见岳父大人</td>\n",
       "      <td>星际迷航3：超越星辰</td>\n",
       "      <td>火星救援</td>\n",
       "      <td>大空头</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ADD_TIME_y</th>\n",
       "      <td>Fri Jan  5 11:35:19 2018</td>\n",
       "      <td>Fri Jan  5 11:36:14 2018</td>\n",
       "      <td>Fri Jan  5 11:35:50 2018</td>\n",
       "      <td>Fri Jan  5 11:35:12 2018</td>\n",
       "      <td>Fri Jan  5 11:35:55 2018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>type</th>\n",
       "      <td>剧情|奇幻|冒险|喜剧</td>\n",
       "      <td>剧情|喜剧|爱情</td>\n",
       "      <td>奇幻|战争|剧情|科幻|冒险|动作</td>\n",
       "      <td>剧情|灾难|冒险|喜剧|科幻</td>\n",
       "      <td>剧情|犯罪|传记|喜剧|历史</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>actors</th>\n",
       "      <td>艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克</td>\n",
       "      <td>罗伯特·德尼罗|本·斯蒂勒|特莉·保罗|布莱思·丹纳|欧文·威尔逊</td>\n",
       "      <td>克里斯·派恩|扎克瑞·昆图|佐伊·索尔达娜|西蒙·佩吉|安东·叶利钦</td>\n",
       "      <td>马特·达蒙|杰西卡·查斯坦|克里斯汀·韦格|杰夫·丹尼尔斯|迈克尔·佩纳</td>\n",
       "      <td>克里斯蒂安·贝尔|史蒂夫·卡瑞尔|瑞恩·高斯林|布拉德·皮特|梅丽莎·里奥</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>region</th>\n",
       "      <td>美国</td>\n",
       "      <td>美国</td>\n",
       "      <td>美国</td>\n",
       "      <td>英国</td>\n",
       "      <td>美国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <td>彼特·道格特|罗纳尔多·德尔·卡门</td>\n",
       "      <td>杰伊·罗奇</td>\n",
       "      <td>林诣彬</td>\n",
       "      <td>雷德利·斯科特</td>\n",
       "      <td>亚当·麦凯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trait</th>\n",
       "      <td>感人|经典|励志</td>\n",
       "      <td>经典|搞笑</td>\n",
       "      <td>经典</td>\n",
       "      <td>经典|励志</td>\n",
       "      <td>经典</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rat</th>\n",
       "      <td>8.7</td>\n",
       "      <td>7.1</td>\n",
       "      <td>7.3</td>\n",
       "      <td>8.4</td>\n",
       "      <td>8.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>enable</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>description</th>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>img</th>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>userid</th>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rmax</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rmin</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ravg</th>\n",
       "      <td>3.85714</td>\n",
       "      <td>3.85714</td>\n",
       "      <td>3.85714</td>\n",
       "      <td>3.85714</td>\n",
       "      <td>3.85714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rcount</th>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rsum</th>\n",
       "      <td>27</td>\n",
       "      <td>27</td>\n",
       "      <td>27</td>\n",
       "      <td>27</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rmedian</th>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               0  \\\n",
       "ID                                         10000   \n",
       "TIME                         2015-10-09 20:02:19   \n",
       "MOVIEID                                 10533913   \n",
       "RATING                                         4   \n",
       "CONTENT                  虽然依然充满了想象力，但突然觉得这部很一般呢。   \n",
       "CREATOR                                   妖怪dodo   \n",
       "ADD_TIME_x                   2018-01-05 15:23:18   \n",
       "NEWDATA                                        0   \n",
       "USERID          cf2349f9c01f9a5cd4050aebd30ab74f   \n",
       "id                                      10533913   \n",
       "name                                       头脑特工队   \n",
       "ADD_TIME_y              Fri Jan  5 11:35:19 2018   \n",
       "type                                 剧情|奇幻|冒险|喜剧   \n",
       "actors       艾米·波勒|菲利丝·史密斯|理查德·坎德|比尔·哈德尔|刘易斯·布莱克   \n",
       "region                                        美国   \n",
       "director                       彼特·道格特|罗纳尔多·德尔·卡门   \n",
       "trait                                   感人|经典|励志   \n",
       "rat                                          8.7   \n",
       "enable                                         1   \n",
       "description                                        \n",
       "img                                                \n",
       "userid          cf2349f9c01f9a5cd4050aebd30ab74f   \n",
       "rmax                                           5   \n",
       "rmin                                           2   \n",
       "ravg                                     3.85714   \n",
       "rcount                                         7   \n",
       "rsum                                          27   \n",
       "rmedian                                        4   \n",
       "\n",
       "                                             1  \\\n",
       "ID                                      100231   \n",
       "TIME                       2009-01-31 22:36:03   \n",
       "MOVIEID                                1294829   \n",
       "RATING                                       4   \n",
       "CONTENT                  开头很好听～～a fool in love   \n",
       "CREATOR                                 妖怪dodo   \n",
       "ADD_TIME_x                 2018-01-19 16:16:23   \n",
       "NEWDATA                                      0   \n",
       "USERID        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
       "id                                     1294829   \n",
       "name                                    拜见岳父大人   \n",
       "ADD_TIME_y            Fri Jan  5 11:36:14 2018   \n",
       "type                                  剧情|喜剧|爱情   \n",
       "actors       罗伯特·德尼罗|本·斯蒂勒|特莉·保罗|布莱思·丹纳|欧文·威尔逊   \n",
       "region                                      美国   \n",
       "director                                 杰伊·罗奇   \n",
       "trait                                    经典|搞笑   \n",
       "rat                                        7.1   \n",
       "enable                                       1   \n",
       "description                                      \n",
       "img                                              \n",
       "userid        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
       "rmax                                         5   \n",
       "rmin                                         2   \n",
       "ravg                                   3.85714   \n",
       "rcount                                       7   \n",
       "rsum                                        27   \n",
       "rmedian                                      4   \n",
       "\n",
       "                                              2  \\\n",
       "ID                                       205834   \n",
       "TIME                        2016-11-25 17:19:18   \n",
       "MOVIEID                                22939161   \n",
       "RATING                                        2   \n",
       "CONTENT                                 特别没意思了。   \n",
       "CREATOR                                  妖怪dodo   \n",
       "ADD_TIME_x                  2018-01-25 13:44:26   \n",
       "NEWDATA                                       0   \n",
       "USERID         cf2349f9c01f9a5cd4050aebd30ab74f   \n",
       "id                                     22939161   \n",
       "name                                 星际迷航3：超越星辰   \n",
       "ADD_TIME_y             Fri Jan  5 11:35:50 2018   \n",
       "type                          奇幻|战争|剧情|科幻|冒险|动作   \n",
       "actors       克里斯·派恩|扎克瑞·昆图|佐伊·索尔达娜|西蒙·佩吉|安东·叶利钦   \n",
       "region                                       美国   \n",
       "director                                    林诣彬   \n",
       "trait                                        经典   \n",
       "rat                                         7.3   \n",
       "enable                                        1   \n",
       "description                                       \n",
       "img                                               \n",
       "userid         cf2349f9c01f9a5cd4050aebd30ab74f   \n",
       "rmax                                          5   \n",
       "rmin                                          2   \n",
       "ravg                                    3.85714   \n",
       "rcount                                        7   \n",
       "rsum                                         27   \n",
       "rmedian                                       4   \n",
       "\n",
       "                                                             3  \\\n",
       "ID                                                      221461   \n",
       "TIME                                       2016-01-03 09:56:48   \n",
       "MOVIEID                                               25864085   \n",
       "RATING                                                       4   \n",
       "CONTENT      虽然也是浩瀚宇宙，但跟诺兰想要传达的完全不一样。全片证明了一个论题：学好数理化，走遍宇宙都不...   \n",
       "CREATOR                                                 妖怪dodo   \n",
       "ADD_TIME_x                                 2018-01-25 15:55:03   \n",
       "NEWDATA                                                      0   \n",
       "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
       "id                                                    25864085   \n",
       "name                                                      火星救援   \n",
       "ADD_TIME_y                            Fri Jan  5 11:35:12 2018   \n",
       "type                                            剧情|灾难|冒险|喜剧|科幻   \n",
       "actors                    马特·达蒙|杰西卡·查斯坦|克里斯汀·韦格|杰夫·丹尼尔斯|迈克尔·佩纳   \n",
       "region                                                      英国   \n",
       "director                                               雷德利·斯科特   \n",
       "trait                                                    经典|励志   \n",
       "rat                                                        8.4   \n",
       "enable                                                       1   \n",
       "description                                                      \n",
       "img                                                              \n",
       "userid                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
       "rmax                                                         5   \n",
       "rmin                                                         2   \n",
       "ravg                                                   3.85714   \n",
       "rcount                                                       7   \n",
       "rsum                                                        27   \n",
       "rmedian                                                      4   \n",
       "\n",
       "                                                 4  \n",
       "ID                                          225496  \n",
       "TIME                           2016-03-20 22:54:09  \n",
       "MOVIEID                                   26303622  \n",
       "RATING                                           4  \n",
       "CONTENT                                       不寒而栗  \n",
       "CREATOR                                     妖怪dodo  \n",
       "ADD_TIME_x                     2018-01-25 16:18:51  \n",
       "NEWDATA                                          0  \n",
       "USERID            cf2349f9c01f9a5cd4050aebd30ab74f  \n",
       "id                                        26303622  \n",
       "name                                           大空头  \n",
       "ADD_TIME_y                Fri Jan  5 11:35:55 2018  \n",
       "type                                剧情|犯罪|传记|喜剧|历史  \n",
       "actors       克里斯蒂安·贝尔|史蒂夫·卡瑞尔|瑞恩·高斯林|布拉德·皮特|梅丽莎·里奥  \n",
       "region                                          美国  \n",
       "director                                     亚当·麦凯  \n",
       "trait                                           经典  \n",
       "rat                                            8.3  \n",
       "enable                                           1  \n",
       "description                                         \n",
       "img                                                 \n",
       "userid            cf2349f9c01f9a5cd4050aebd30ab74f  \n",
       "rmax                                             5  \n",
       "rmin                                             2  \n",
       "ravg                                       3.85714  \n",
       "rcount                                           7  \n",
       "rsum                                            27  \n",
       "rmedian                                          4  "
      ]
     },
     "execution_count": 25,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data.head().T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 122
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 45957,
     "status": "ok",
     "timestamp": 1545737497048,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "p0eblB6mpN6N",
    "outputId": "f2e123cb-1910-45b3-b688-1b495cbd75a2"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdocs.test%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.photos.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fpeopleapi.readonly&response_type=code\n",
      "\n",
      "Enter your authorization code:\n",
      "··········\n",
      "Mounted at /content/drive\n"
     ]
    }
   ],
   "source": [
    "from google.colab import drive\n",
    "drive.mount('/content/drive')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "6IuArkEolyAn"
   },
   "outputs": [],
   "source": [
    "time_now_str = datetime.datetime.now().strftime(\"%Y-%m-%d-%H-%M-%S\")\n",
    "df_data.to_csv('/content/drive/My Drive/colabnotebook/comment_origin_data_%s.csv' % time_now_str, sep='\\t', encoding='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 510
    },
    "colab_type": "code",
    "collapsed": false,
    "executionInfo": {
     "elapsed": 891,
     "status": "ok",
     "timestamp": 1545737872648,
     "user": {
      "displayName": "Cheng Gavin",
      "photoUrl": "",
      "userId": "16557339152332771497"
     },
     "user_tz": -480
    },
    "id": "d6KzitU-o0sB",
    "outputId": "51de9fd6-5cd8-4795-ca59-e8d08c973256"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ID                                             226336\n",
       "TIME                              2016-12-12 18:59:32\n",
       "MOVIEID                                      26416603\n",
       "RATING                                              5\n",
       "CONTENT        本来不抱期望，只是想去一次看两场电影，没想到那么好看！真的超好看的强烈安利！\n",
       "CREATOR                                      Amberose\n",
       "ADD_TIME_x                        2018-01-25 16:23:33\n",
       "NEWDATA                                             0\n",
       "USERID               954c2bf7a96d309c7bd4fe0dd0c1290f\n",
       "id                                           26416603\n",
       "name                                             萨利机长\n",
       "ADD_TIME_y                   Fri Jan  5 11:35:33 2018\n",
       "type                                   剧情|灾难|冒险|传记|历史\n",
       "actors               汤姆·汉克斯|艾伦·艾克哈特|劳拉·琳妮|杰瑞·费拉拉|安娜·冈\n",
       "region                                             美国\n",
       "director                                    克林特·伊斯特伍德\n",
       "trait                                        感人|经典|励志\n",
       "rat                                               8.3\n",
       "enable                                              1\n",
       "description                                          \n",
       "img                                                  \n",
       "userid               954c2bf7a96d309c7bd4fe0dd0c1290f\n",
       "rmax                                                5\n",
       "rmin                                                4\n",
       "ravg                                            4.625\n",
       "rcount                                             24\n",
       "rsum                                              111\n",
       "rmedian                                             5\n",
       "Name: 10000, dtype: object"
      ]
     },
     "execution_count": 29,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data.iloc[10000]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "57YbfbTZJc4c"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "anaconda-cloud": {},
  "colab": {
   "collapsed_sections": [],
   "name": "4_prepare_rating_matrix.ipynb",
   "provenance": [],
   "version": "0.3.2"
  },
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
